#include "CFPS.h"
CFPS CFPS::FPSControl;

CFPS::CFPS()
{
    OldTime     = 0;
    LastTime    = 0;
    SpeedFactor = 0;
    Frames      = 0;
    NumFrames   = 0;
}
 
void CFPS::OnLoop()
{
    int currentTicks = SDL_GetTicks();

	//If it's been a second, re-calculate FPS (not used in speed factor)
    if(OldTime + 1000 < currentTicks)
    {
        OldTime = currentTicks;
        NumFrames = Frames;
        Frames = 0;
		std::cout << "FPS : " << GetFPS();
    }

	float timeSliceSeconds = (currentTicks - LastTime) / 1000.0f;
	//Multiply standardized (across machines) time slice by a constant to speed up game feel
    SpeedFactor = timeSliceSeconds * SPEED_FACTOR_CONSTANT;

    LastTime = currentTicks;
    Frames++;
}
 
int CFPS::GetFPS()
{
    return NumFrames;
}
 
float CFPS::GetSpeedFactor()
{
    return SpeedFactor;
}